package main

import (
	"fmt"
	"time"
)

func main(){

	timeout()
	selectDefault()
	fmt.Println("main end")
}

func timeLoop(){
	tickTimer := time.NewTicker(1*time.Second)
	barTimer := time.NewTicker(60*time.Second)
	for {
		select {
		case <- tickTimer.C:
			fmt.Println("tick")
		case <- barTimer.C:
			fmt.Println("bar")
		}
	}
}
func timeout(){
	timeout := make (chan bool, 1)
	go func() {
		time.Sleep(1e9) // sleep one second
		timeout <- true
	}()
	ch := make (chan int)
	select {
	case <- ch:
	case <- timeout:
		fmt.Println("timeout!")
	}
}

func selectDefault(){
	ch1 := make(chan int, 1)
	ch2 := make(chan int, 2)
	ch1 <- 10
	select {
		case <- ch1:
			fmt.Println("ch1")
			case <- ch2:
				fmt.Println("ch2")
	default:
		fmt.Println("default")

	}
}